<?php

class Application_Model_Storage extends Engine_Model_Abstract
{
  public function __construct($file_id = null)
  {
    parent::__construct(new Application_Model_DbTable_Storages(), $file_id);
  }

  public function save()
  {
    $this->modified_date = date("Y-m-d H:i:s");
    parent::save();
  }

  public function bridge($path, $type = null)
  {
    $this->size = filesize($path);
    $this->creation_date = date("Y-m-d H:i:s");
    $this->setStoragePath($path);
    $this->setType($type);
  }

  public function setStoragePath($path)
  {
    $path = explode('\\', $path);
    array_shift($path);
    array_shift($path);
    array_shift($path);
    $path = '/' . implode('/', $path);
    if ($path) {
      $this->storage_path = $path;
    }
  }

  public function getStoragePath()
  {
    return $this->storage_path;
  }

  public function setType($type)
  {
    if ($type) {
      $this->type = $type;
    }
  }

  public function getType()
  {
    return $this->type;
  }

  public function getParentFileId()
  {
    return $this->parent_file_id;
  }

  public function setParentFileId($id)
  {
    if ($id) {
      $this->parent_file_id = $id;
    }
  }

  public function getFileId()
  {
    return $this->file_id;
  }

}

